package com.baidu.fenfayun.demo.home
import android.content.*
import android.view.Gravity;
import android.view.View
import android.view.ViewGroup
import android.widget.AbsListView
import android.widget.BaseAdapter
import com.baidu.yun.gameline.R
import android.view.*
import android.widget.*
import android.graphics.drawable.*
import android.graphics.*

import org.jetbrains.anko.*
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.util.QMUIResHelper
import com.qmuiteam.qmui.util.QMUIViewHelper

import com.baidu.fenfayun.demo.model.QDItemDescription
import com.baidu.fenfayun.demo.auth.*
import com.baidu.fenfayun.demo.act.*
import com.baidu.fenfayun.demo.util.*
import com.qmuiteam.qmui.widget.grouplist.*

import net.steamcrafted.materialiconlib.*
import com.qmuiteam.qmui.alpha.QMUIAlphaImageButton

import kotlinx.android.synthetic.main.home_my_layout.view.*
class HomeMyController(context:Context): LayoutController(context,R.layout.home_my_layout) {



   var mQDItemDescription:QDItemDescription?  = null
   override fun getTitle():String  {
      return "我的"
   }

   fun initGroupListView(){
      val context = getContext()

      val itemWithSwitch = groupListView.createItemView("是否登陆");
      itemWithSwitch.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_SWITCH)
      itemWithSwitch.getSwitch().setOnCheckedChangeListener(object:CompoundButton.OnCheckedChangeListener {
         public override fun onCheckedChanged(buttonView:CompoundButton , isChecked:Boolean) {
            context.longToast( "checked = " + isChecked)
         }
      })

      val itemWithChevron = groupListView.createItemView("跳转");
      itemWithChevron.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON)
      val img = IconUtil.getDraw(getContext(),MaterialDrawableBuilder.IconValue.INFORMATION)
      img.setColor(Color.BLACK)
      itemWithChevron.setImageDrawable(img.build())

      QMUIGroupListView.newSection(context)
      .setTitle(" ")
      .setDescription(" ")
      .addItemView(groupListView.createItemView("退出登录"),View.OnClickListener{
         val smartLogin = SmartLoginFactory.build(LoginType.CustomLogin)
         smartLogin.logout(context)
         val intent = Intent(getContext(), LoginAct::class.java)
         getBase().startActivity(intent)
      })
      .addTo(groupListView)


      QMUIGroupListView.newSection(context)
      .setTitle(" ")
      .addItemView(itemWithChevron,View.OnClickListener{

      })
      .addItemView(itemWithSwitch,View.OnClickListener{

      })
      .addTo(groupListView)

   }  
   override fun initView() {
      super.initView()
      addRightImageButton(R.mipmap.icon_tabbar_lab_selected, QMUIViewHelper.generateViewId()).setOnClickListener( {
         Toast.makeText(getContext(), "开始搜索", Toast.LENGTH_SHORT).show()
         startFragment(SearchFragment())
      }
)
initGroupListView()
   }
   fun addRightImageButton(drawableResId:Int, viewId:Int):QMUIAlphaImageButton  {
      val rightButton = IconUtil.generateImageButton(drawableResId,getContext())
      rightButton.setImageDrawable(IconUtil.getImage(getContext(),MaterialDrawableBuilder.IconValue.MAGNIFY))
      topbar.addRightView(rightButton, viewId, topbar.generateTopBarImageButtonLayoutParams())
      return rightButton
   }
}
